package framework.distributed;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 分散モデルは異なるJVMで実行されるため、mainが必要になる。
 *
 * @author uehara
 *
 */
public class HubServer extends framework.sequential.HubServer {

	int port;

	public HubServer(int port) {
		super();
		this.port = port;
	}

	public void run() {
		try {
			ServerSocket ss = new ServerSocket(port);
			while (true) {
				Socket s = ss.accept();
				OutputStream out = s.getOutputStream();
				InputStream in = s.getInputStream();
				// TODO
				s.close();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		int port = Integer.parseInt(args[0]);
		HubServer hub = new HubServer(port);
		hub.run();
	}
}
